package cn.bdqn.asecu.controller;

import cn.bdqn.asecu.service.AttributeSettingService;
import cn.bdqn.pojo.AttriSetting;
import cn.bdqn.pojo.Attributes;
import cn.bdqn.vo.AttrAndSetting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class AttributeSettingController {

    @Autowired
    AttributeSettingService attributeSettingService;

    /**
     * 页面加载时获取数据
     * @param model
     * @return
     */
    @RequestMapping("attribute-setting")
    public String html(Model model){
        List<AttriSetting> attrSettingList = attributeSettingService.getAttrSetting();
        model.addAttribute("attrSettingList",attrSettingList);
        return "attribute-setting";
    }
    @RequestMapping("showAttr")
    @ResponseBody
    public List<AttrAndSetting> showAttr(Integer id){
        List<AttrAndSetting> attrAndSettings = attributeSettingService.getAttr(id);
        return attrAndSettings;
    }
    @RequestMapping("attrsetting-add")
    public String attrsetting_add(Model model,Integer id){
        List<Attributes> attrManagement = attributeSettingService.getAttrManagement();
        model.addAttribute("attrManagement",attrManagement);
        model.addAttribute("id",id);
        return "attrsetting-add";
    }
    @RequestMapping("addSetting")
    @ResponseBody
    public String addSetting(Integer settingId,Integer id){
        boolean b = attributeSettingService.addSetting(settingId, id);
        return b?"200":"error";
    }

    @RequestMapping("attrsetting-edit")
    public String attrsetting_edit(Model model,Integer id){
        AttrAndSetting as = attributeSettingService.findOne(id);
        model.addAttribute("as",as);
        return "attrsetting-edit";
    }

    @RequestMapping("editAttrsetting")
    @ResponseBody
    public String editAttrsetting(AttrAndSetting attrAndSetting){
        boolean b = attributeSettingService.editAttrsetting(attrAndSetting);
        return b?"200":"error";
    }

    @RequestMapping("delAttrsetting")
    @ResponseBody
    public String delAttrsetting(Integer sid){
        boolean b = attributeSettingService.delAttrsetting(sid);
        return b?"200":"error";
    }

}
